import { password}  from "../../../../js/modules/account.js";
const info = require("../../../../js/modules/info.js");
import { forms, storage, util} from '../../../../js/util';
import {
  router
} from '../../../../js/router';
import authorize from '../../../../js/modules/authorize.js'
import BasePage from '../../../../js/common/base-page'
import { setStorageSync } from "../../../../js/compatible.js";
const app = getApp()

BasePage({
  pageKey:"passwordModify",

  /**
   * 页面的初始数据
   */
  data: {
    forms: {
      LoginPwd: {
        value: "",
        validate: "isnull",
        error: "请输入登录密码"
      },
      PicVerifyCode: {
        value: "",
        validate: "isnull",
        error: "请输入正确的校验码"
      },
      Password: {
        value: "",
        validate: "isnull|pwd",
        error: "密码长度为6-20位"
      },
      RepPassword: {
        value: "",
        validate: "isnull|pwd",
        error: "密码长度为6-20位"
      },
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获得图片验证码组件
    this.picVerifyCode = this.selectComponent("#PicVerifyCode");
    //设置回调
    this.picVerifyCode.data.callback = info.getPicVerifyCode;
    //调用一次图片验证码
    this.picVerifyCode.bindPicVerifyCode();
  },
  /**
     * 表单值绑定
     */
  bindFormValue: function (e) {
    e = e.detail;
    this.data.forms[e.target.id].value = e.detail.value;

  },
/**
 * 
 */
  onSubmitEvent:function(e){
    var oldPassword = this.data.forms.LoginPwd.value;
    var newPassword = this.data.forms.Password.value;
    var newAgain = this.data.forms.RepPassword.value;
    var picVerifyCode = this.data.forms.PicVerifyCode.value;
    if (oldPassword == "") {
      util.tips("旧密码不能为空！");
      return;
    }
    if (newPassword == "" || newPassword.length < 6) {
      util.tips("请输入至少6位新密码！");
      return;
    }
    if (newPassword != newAgain) {
      util.tips("两次密码不一致！");
      return;
    }
    if (picVerifyCode.length == 0) {
      util.tips("请输入验证码！");
      return;
    }
    password.update_login_pwd("store",this.data.forms);

  },
  /**
   * 取消
   */
  onCancelEvent: function (e) {
    setStorageSync('tabindex', app.dns.centerNum);
    router.switchTab({
      path: "center"
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})